{template 'common/header'}
 <!-- start -->
 <div class="panel we7-panel ng-scope">
  <div class="panel-heading">添加广告</div>
    <div class="panel-body we7-padding">
      <div class="form-horizontal">  
        <div class="form-group">
            <label class="col-sm-2 control-label">广告标题</label>
            <div class="col-sm-8">
                <input class="form-control required" type="text" id="title" name="title" placeholder="请填写广告标题" value="{$ad['title']}">
            </div>
          </div> 
          <div class="form-group">
              <label class="col-sm-2 control-label">广告图片</label>
              <div class="col-sm-8">           
                  {php echo tpl_form_field_image('img',$ad['img']);}                           
              </div>              
          </div> 
      <div class="form-group">
        <label class="col-sm-2 control-label" >是否显示</label>
          <div class="col-sm-8">
          <label class="radio-inline">
            <input type="radio" name="ishide" id="ishide" value="1" {if $ad['ishide']=='1'}checked{else}{/if}> 是
          </label>
          <label class="checkbox-inline">
            <input type="radio" name="ishide" id="ishide" value="0" {if $ad['ishide']=='0'}checked{else}{/if}> 否
          </label>   
        </div>
      </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">排序顺序</label>
        <div class="col-sm-8">
            <input class="form-control required" type="number" id="orderid" name="orderid" placeholder="请填写排序值越大越靠前" value="{$ad['orderid']}">
        </div>
      </div>
      {if $goods}
      <div class="form-group">
        <label class="col-sm-2 control-label">链接产品</label>
        <div class="col-sm-8">
                  <select class="form-control"  id="linkgoodsid" name="linkgoodsid">
                    <option value="0">设置为空链接</option>
                    {loop $goods $k $o}
                    <option value="{$o['id']}" {if $ad['linkgoodsid']==$o['id']}selected{else}{/if}>{$o['goodsname']}</option>
                    {/loop}
                  </select>
        </div>
      </div>
      {else}
      {/if}    
        <div class="form-group">
            <label class="col-sm-2 control-label">有效期限</label>
            <div class="col-sm-8">           
                {php echo tpl_form_field_date('term',$ad['term']);}                           
            </div>              
        </div> 
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
         <input type="submit" id="submit" name="submit" class="btn btn-info" value="确认提交">
      </div>
      </div>        
      </div>    
    </div>
 </div> 
<style type="text/css">.right-content{padding: 0;}</style>
<link rel="stylesheet" href="{MODULE_URL}public/css/Toast.css">
<script src="{MODULE_URL}public/js/Toast.js"></script>
 <script>
$(document).ready(function(){
       $("#submit").on(
            "click",function(){
              var title = $.trim($('#title').val());
              var img = $.trim($('input[name="img"]').val());
              var ishide = $("input[name='ishide']:checked").val();
              var orderid = $.trim($('#orderid').val());
              var link = $.trim($('#link').val());
              var term = $.trim($('input[name="term"]').val());
              if(img == ""||term == ""){
                mqToast({type:1,context: '广告图片或有效期限不能为空!'});
                return false;
              }
                 $.ajax({
                     url:"{php echo $this->createWebUrl('save_adadd');}&version_id="+"{$_GPC['version_id']}",
                     data:{title:title,img:img,ishide:ishide,orderid:orderid,link:link,term:term},
                     dataType:"json",
                     type:"post",
                    success:function(res){
                       if(res.status== 1){
                           mqToast({type:1,context:res.msg});
                          setTimeout(function(){
                                  window.location.reload();
                                },2000);
                           return false;
                       }else{
                           mqToast({type:1,context: res.msg});
                           return false;
                       }
                    }
                })
        })
});
</script>
 {template 'common/footer'}